package com.google.android.material.textfield;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ValueAnimator;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import c.b.a.b.j;
import com.google.android.material.textfield.TextInputLayout;

class a extends e {
    /* access modifiers changed from: private */

    /* renamed from: d  reason: collision with root package name */
    public final TextWatcher f2401d = new C0102a();
    private final TextInputLayout.f e = new b();
    /* access modifiers changed from: private */
    public AnimatorSet f;
    /* access modifiers changed from: private */
    public ValueAnimator g;

    /* renamed from: com.google.android.material.textfield.a$a  reason: collision with other inner class name */
    class C0102a implements TextWatcher {
        C0102a() {
        }

        public void afterTextChanged(Editable editable) {
            if (!a.j(editable)) {
                a.this.f.cancel();
                a.this.g.start();
            } else if (!a.this.f2421a.E()) {
                a.this.g.cancel();
                a.this.f.start();
            }
        }

        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }

        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }
    }

    class b implements TextInputLayout.f {
        b() {
        }

        public void a(TextInputLayout textInputLayout) {
            EditText editText = textInputLayout.getEditText();
            textInputLayout.setEndIconVisible(a.j(editText.getText()));
            textInputLayout.setEndIconCheckable(false);
            editText.removeTextChangedListener(a.this.f2401d);
            editText.addTextChangedListener(a.this.f2401d);
        }
    }

    class c implements View.OnClickListener {
        c() {
        }

        public void onClick(View view) {
            a.this.f2421a.getEditText().setText((CharSequence) null);
        }
    }

    class d extends AnimatorListenerAdapter {
        d() {
        }

        public void onAnimationStart(Animator animator) {
            a.this.f2421a.setEndIconVisible(true);
        }
    }

    class e extends AnimatorListenerAdapter {
        e() {
        }

        public void onAnimationEnd(Animator animator) {
            a.this.f2421a.setEndIconVisible(false);
        }
    }

    class f implements ValueAnimator.AnimatorUpdateListener {
        f() {
        }

        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            a.this.f2423c.setAlpha(((Float) valueAnimator.getAnimatedValue()).floatValue());
        }
    }

    class g implements ValueAnimator.AnimatorUpdateListener {
        g() {
        }

        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float floatValue = ((Float) valueAnimator.getAnimatedValue()).floatValue();
            a.this.f2423c.setScaleX(floatValue);
            a.this.f2423c.setScaleY(floatValue);
        }
    }

    a(TextInputLayout textInputLayout) {
        super(textInputLayout);
    }

    private ValueAnimator h(float... fArr) {
        ValueAnimator ofFloat = ValueAnimator.ofFloat(fArr);
        ofFloat.setInterpolator(c.b.a.b.m.a.f1874a);
        ofFloat.setDuration(100);
        ofFloat.addUpdateListener(new f());
        return ofFloat;
    }

    private ValueAnimator i() {
        ValueAnimator ofFloat = ValueAnimator.ofFloat(new float[]{0.8f, 1.0f});
        ofFloat.setInterpolator(c.b.a.b.m.a.f1877d);
        ofFloat.setDuration(150);
        ofFloat.addUpdateListener(new g());
        return ofFloat;
    }

    /* access modifiers changed from: private */
    public static boolean j(Editable editable) {
        return editable.length() > 0;
    }

    private void k() {
        ValueAnimator i = i();
        ValueAnimator h = h(0.0f, 1.0f);
        AnimatorSet animatorSet = new AnimatorSet();
        this.f = animatorSet;
        animatorSet.playTogether(new Animator[]{i, h});
        this.f.addListener(new d());
        ValueAnimator h2 = h(1.0f, 0.0f);
        this.g = h2;
        h2.addListener(new e());
    }

    /* access modifiers changed from: package-private */
    public void a() {
        this.f2421a.setEndIconDrawable(b.a.k.a.a.d(this.f2422b, c.b.a.b.e.mtrl_ic_cancel));
        TextInputLayout textInputLayout = this.f2421a;
        textInputLayout.setEndIconContentDescription(textInputLayout.getResources().getText(j.clear_text_end_icon_content_description));
        this.f2421a.setEndIconOnClickListener(new c());
        this.f2421a.c(this.e);
        k();
    }
}
